################################################################################
# hse firmware
################################################################################
HSE_FIRMWARE_NAME := hse-firmware
HSE_FIRMWARE_VERSION := $(call qstrip,$(BR2_PACKAGE_S32_HSE_FIRMWARE_VERSION))
# 定义机器类型和 SoC 版本
HSE_MACHINE = $(call qstrip,$(BR2_PACKAGE_S32_HSE_FIRMWARE_MACHINE))
HSE_SOC_VERSION = $(call qstrip,$(BR2_PACKAGE_S32_HSE_FIRMWARE_SOC_VERSION))
# 构建固件包名称
HSE_FIRMWARE_PKG = HSE_FW_${HSE_MACHINE}_${HSE_FIRMWARE_VERSION}
HSE_FIRMWARE_SITE = package/nxp/s32/hse/hse-firmware/$(HSE_FIRMWARE_PKG)
HSE_FIRMWARE_SITE_METHOD = local

# 安装固件到目标目录
define HSE_FIRMWARE_INSTALL_TARGET_CMDS
	$(INSTALL) -D -m 0644 $(@D)/hse/bin/$(HSE_SOC_VERSION)*.bin.pink \
		$(TARGET_DIR)/lib/firmware/s32cc_hse_fw.bin

	$(INSTALL) -d $(TARGET_DIR)/usr/include/hse-interface
	cp -r $(@D)/interface/* $(TARGET_DIR)/usr/include/hse-interface/
endef

#安装到 staging 目录中
define HSE_FIRMWARE_INSTALL_STAGING_CMDS
	$(INSTALL) -D -m 0644 $(@D)/hse/bin/$(HSE_SOC_VERSION)*.bin.pink \
		$(STAGING_DIR)/lib/firmware/s32cc_hse_fw.bin

	$(INSTALL) -D -m 0644 $(@D)/hse/bin/$(HSE_SOC_VERSION)*.bin.pink \
		$(BINARIES_DIR)/s32cc_hse_fw.bin

	$(INSTALL) -d $(STAGING_DIR)/usr/include/hse-interface
	cp -R $(@D)/interface $(STAGING_DIR)/usr/include/hse-interface/

	$(INSTALL) -D -m 0644 $(@D)/hse/bin/$(HSE_SOC_VERSION)*.bin.pink \
        	$(HOST_DIR)/$(GNU_TARGET_NAME)/sysroot/usr/lib/firmware/s32cc_hse_fw.bin

	$(INSTALL) -d $(HOST_DIR)/$(GNU_TARGET_NAME)/sysroot/usr/include/hse-interface
	cp -R $(@D)/interface $(HOST_DIR)/$(GNU_TARGET_NAME)/sysroot/usr/include/hse-interface/
endef
HSE_FIRMWARE_INSTALL_STAGING = YES

$(eval $(generic-package))
